package request

import (
	"strings"

	"github.com/gin-gonic/gin"
	"lab.com/define/errorcode"
)

// PaperAddReq .
type PaperAddReq struct {
	Title            string `json:"title" form:"title" validate:"required" comment:"论文标题"`
	PublicationType  int    `json:"publication_type" form:"publication_type" validate:"required" comment:"发表在会议/期刊"`
	PublisherFull    string `json:"publisher_full" form:"publisher_full" validate:"required" comment:"会议/期刊全称"`
	PublisherAcronym string `json:"publisher_acronym" form:"publisher_acronym" validate:"required,max=30" comment:"会议/期刊简称"`
	Abstract         string `json:"abstract" form:"abstract" validate:"required" comment:"摘要"`
	SourceLink       string `json:"source_link" form:"source_link" validate:"required" comment:"论文原文链接"`
	PublicationDate  string `json:"publication_date" form:"publication_date" validate:"required" comment:"出版日期"`
	CcfRank          int    `json:"ccf_rank" form:"ccf_rank" validate:"required" comment:"CCF等级"`
	Tags             string `json:"tags" form:"tags" validate:"required" comment:"标签"`
}

// CheckInputParams return input params
func (paper *PaperAddReq) CheckInputParams(c *gin.Context) error {

	if err := c.ShouldBind(paper); err != nil {
		return err
	}
	if errs, err := Validate(paper); err != nil {
		return errorcode.New(errorcode.ErrParams, strings.Join(errs, ","), nil)
	}

	return nil
}

// PaperEditReq .
type PaperEditReq struct {
	ID               int    `json:"id" form:"id" validate:"required" comment:"论文id"`
	Title            string `json:"title" form:"title" validate:"required" comment:"论文标题"`
	PublicationType  int    `json:"publication_type" form:"publication_type" validate:"required" comment:"发表在会议/期刊"`
	PublisherFull    string `json:"publisher_full" form:"publisher_full" validate:"required" comment:"会议/期刊全称"`
	PublisherAcronym string `json:"publisher_acronym" form:"publisher_acronym" validate:"required,max=30" comment:"会议/期刊简称"`
	Abstract         string `json:"abstract" form:"abstract" validate:"required" comment:"摘要"`
	SourceLink       string `json:"source_link" form:"source_link" validate:"required" comment:"论文原文链接"`
	PublicationDate  string `json:"publication_date" form:"publication_date" validate:"required" comment:"出版日期"`
	CcfRank          int    `json:"ccf_rank" form:"ccf_rank" validate:"required" comment:"CCF等级"`
	Tags             string `json:"tags" form:"tags" validate:"required" comment:"标签"`
}

// CheckInputParams return input params
func (paper *PaperEditReq) CheckInputParams(c *gin.Context) error {

	if err := c.ShouldBind(paper); err != nil {
		return err
	}
	if errs, err := Validate(paper); err != nil {
		return errorcode.New(errorcode.ErrParams, strings.Join(errs, ","), nil)
	}

	return nil
}

// PaperDeleteReq .
type PaperDeleteReq struct {
	ID int `json:"id" form:"id" validate:"required" comment:"论文id"`
}

// CheckInputParams return input params
func (paper *PaperDeleteReq) CheckInputParams(c *gin.Context) error {

	if err := c.ShouldBind(paper); err != nil {
		return err
	}
	if errs, err := Validate(paper); err != nil {
		return errorcode.New(errorcode.ErrParams, strings.Join(errs, ","), nil)
	}

	return nil
}

// PaperListReq .
type PaperListReq struct {
	Title                string `json:"title" form:"title"  comment:"论文标题"`
	PublicationType      int    `json:"publication_type" form:"publication_type"  comment:"发表在会议/期刊"`
	PublicationDateStart string `json:"publication_date_start" form:"publication_date_start" comment:"出版日期起始"`
	PublicationDateEnd   string `json:"publication_date_end" form:"publication_date_end" comment:"出版日期截止"`
	CcfRank              int    `json:"ccf_rank" form:"ccf_rank"  comment:"CCF等级"`
	PublisherAcronym     string `json:"publisher_acronym" form:"publisher_acronym"  comment:"会议/期刊简称"`
	Tags                 string `json:"tags" form:"tags"  comment:"标签"`
	PageOffset
}

// CheckInputParams return input params
func (paper *PaperListReq) CheckInputParams(c *gin.Context) error {

	if err := c.ShouldBind(paper); err != nil {
		return err
	}
	if errs, err := Validate(paper); err != nil {
		return errorcode.New(errorcode.ErrParams, strings.Join(errs, ","), nil)
	}

	paper.ParseOffset()
	return nil
}

// PaperDetailReq .
type PaperDetailReq struct {
	ID int `json:"id" form:"id" validate:"required" comment:"论文id"`
}

// CheckInputParams return input params
func (paper *PaperDetailReq) CheckInputParams(c *gin.Context) error {

	if err := c.ShouldBind(paper); err != nil {
		return err
	}
	if errs, err := Validate(paper); err != nil {
		return errorcode.New(errorcode.ErrParams, strings.Join(errs, ","), nil)
	}

	return nil
}

// PaperDetailRes .
type PaperDetailRes struct {
	ID                int            `json:"id"`
	Title             string         `json:"title" `
	PublicationType   string         `json:"publication_type" `
	PublicationTypeID int            `json:"publication_type_id"`
	PublisherFull     string         `json:"publisher_full" `
	PublisherAcronym  string         `json:"publisher_acronym" `
	Abstract          string         `json:"abstract" `
	SourceLink        string         `json:"source_link" `
	PublicationDate   string         `json:"publication_date" `
	CcfRank           string         `json:"ccf_rank" `
	CcfRankID         int            `json:"ccf_rank_id"`
	Tags              []TagBasicInfo `json:"tags" `
}

// PaperBasicInfo 论文列表信息
type PaperBasicInfo struct {
	ID                int            `json:"id"`
	Title             string         `json:"title" `
	PublicationType   string         `json:"publication_type" `
	PublicationTypeID int            `json:"publication_type_id"`
	PublisherFull     string         `json:"publisher_full" `
	PublisherAcronym  string         `json:"publisher_acronym" `
	Abstract          string         `json:"abstract" `
	SourceLink        string         `json:"source_link" `
	PublicationDate   string         `json:"publication_date" `
	CcfRank           string         `json:"ccf_rank" `
	CcfRankID         int            `json:"ccf_rank_id"`
	Tags              []TagBasicInfo `json:"tags" `
}

// PaperListRes 论文列表返回结果
type PaperListRes struct {
	List  []PaperBasicInfo `json:"list"`
	Count int              `json:"count"`
}

// TagAddReq .
type TagAddReq struct {
	TagName string `json:"tag_name" form:"tag_name" validate:"required,max=255" comment:"标签名"`
}

// CheckInputParams return input params
func (tag *TagAddReq) CheckInputParams(c *gin.Context) error {

	if err := c.ShouldBind(tag); err != nil {
		return err
	}
	if errs, err := Validate(tag); err != nil {
		return errorcode.New(errorcode.ErrParams, strings.Join(errs, ","), nil)
	}

	return nil
}

// TagEditReq .
type TagEditReq struct {
	ID      int    `json:"id" form:"id" validate:"required" comment:"标签id"`
	TagName string `json:"tag_name" form:"tag_name" validate:"required,max=255" comment:"标签名"`
}

// CheckInputParams return input params
func (tag *TagEditReq) CheckInputParams(c *gin.Context) error {

	if err := c.ShouldBind(tag); err != nil {
		return err
	}
	if errs, err := Validate(tag); err != nil {
		return errorcode.New(errorcode.ErrParams, strings.Join(errs, ","), nil)
	}

	return nil
}

// TagDeleteReq .
type TagDeleteReq struct {
	ID int `json:"id" form:"id" validae:"required" comment:"标签id"`
}

// CheckInputParams return input params
func (tag *TagDeleteReq) CheckInputParams(c *gin.Context) error {

	if err := c.ShouldBind(tag); err != nil {
		return err
	}
	if errs, err := Validate(tag); err != nil {
		return errorcode.New(errorcode.ErrParams, strings.Join(errs, ","), nil)
	}

	return nil
}

// TagListReq .
type TagListReq struct {
	TagName string `json:"tag_name" form:"tag_name" comment:"标签名称"`
	PageOffset
}

// CheckInputParams return input params
func (tag *TagListReq) CheckInputParams(c *gin.Context) error {

	if err := c.ShouldBind(tag); err != nil {
		return err
	}
	if errs, err := Validate(tag); err != nil {
		return errorcode.New(errorcode.ErrParams, strings.Join(errs, ","), nil)
	}

	tag.ParseOffset()
	return nil
}

// TagBasicInfo .
type TagBasicInfo struct {
	ID      int    `json:"id"`
	TagName string `json:"tag_name"`
}

// TagListRes .
type TagListRes struct {
	List  []TagBasicInfo `json:"list"`
	Count int            `json:"count"`
}
